package C;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class C67 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Map<String,String> map = new HashMap<>();
        while(sc.hasNextLine()) {
            String line = sc.nextLine();
//            System.out.println(line.split(" ").length);
            if (line.split(" ").length!=2) {
                break;
            }
            map.put(line.split(" ")[0], line.split(" ")[1]);
        }
        getResult(map);
    }

    public static void getResult(Map<String,String> map) {
        int kinds = (int)map.values().stream().distinct().count();
        if (kinds!=2) System.out.println("NULL");
        if (!map.values().contains("A")) {
            map.entrySet()
                    .stream()
                    .filter(entry-> entry.getValue().equals("B"))
                    .sorted(Map.Entry.comparingByKey())
                    .forEach(entry-> System.out.println(entry.getKey()));
        } else if (!map.values().contains("B")) {
            map.entrySet()
                    .stream()
                    .filter(entry-> entry.getValue().equals("C"))
                    .sorted(Map.Entry.comparingByKey())
                    .forEach(entry-> System.out.println(entry.getKey()));
        } else {
            map.entrySet()
                    .stream()
                    .filter(entry-> entry.getValue().equals("A"))
                    .sorted(Map.Entry.comparingByKey())
                    .forEach(entry-> System.out.println(entry.getKey()));
        }
    }
}
